<template>
	<div>
		<el-tabs v-model="activeName">
			<el-tab-pane v-for="(item, index) in tabsList" :key="index" :label="item.label" :name="item.value"> </el-tab-pane>

			<div class="content-card">
				<html-label title="基本信息">
					<el-button v-if="activeName == 'BaseDetail'"  v-auth="[nowRowData.isOperate==1,baseConfig.auth.edit]" type="primary" @click="handleOperate('edit')">
						修改档案
					</el-button>
				</html-label>

				<component v-if="!loading" class="pd10" :is="whickComm[activeName]" :soleKey="`dpProfessor-${nowRowData.idCard}`"  @refresh="handleRefresh" :nowRowData="nowRowData"></component>
			</div>
		</el-tabs>
	</div>
</template>

<script setup lang="ts">
import apiMod from '@/apiMod'
import { getAreaObj } from '@/utils/util'
import BaseDetail from './BaseDetail/index.vue'
import DataChangeLog from '@/views/datacenter/components/DataChangeLog/index.vue'
import { baseConfig } from '../config'
import { useOperate } from '@/views/datacenter/hooks/useConfig'
import bus from '@/utils/eventbus'
import { useCommonStore } from '@/stores/common'
const {setLoading} = useCommonStore()
const { onDelete } = useOperate(2)

const whickComm = {
	BaseDetail,
  DataChangeLog
}
type Props = {
	nowRowData?: any
}
const props = withDefaults(defineProps<Props>(), {})
provide('nowRowData', props.nowRowData)

const emit = defineEmits(['refresh', 'rechange'])
const loading = ref(false)

const tabsList: any = [
	{ label: '基础信息', value: 'BaseDetail' },
	{ label: '信息编辑记录', value: 'DataChangeLog' },
]
const activeName = ref('BaseDetail')
let nowData = ref({})
provide('nowRowData', nowData)

const handleRefresh = () => {
	emit('refresh')
}

const handleOperate = (type) => {
	if (type == 'delete') {
		onDelete(props.nowRowData[baseConfig.rowKey], baseConfig.api.delete, props.nowRowData.professorName).then(() => {
			emit('refresh')
		})
		return
	} else {
		emit('rechange', 'Rechange', props.nowRowData, '修改档案')
	}
}

bus.on('menu-operate', (res) => {
	if (res.pageName == baseConfig.pageName) {
		handleOperate(res.operate)
	}
})

const getInitData = () => {
  setLoading(true)
	apiMod.view_dpProfessor_view(props.nowRowData.id).then((res) => {
		nowData.value = {
			...(res.data || props.nowRowData),
			areasName: getAreaObj(res.data, ''),
		}
    setLoading(false)
	})
}

onMounted(() => {
	getInitData()
})
</script>

<style scoped></style>
